const Sequelize = require('sequelize')
const db = require('../db')
const RoleModel = require('./role.js')
//定义地址实体对象模型
const User = db.define(
  'User',
  {
    id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
    userCode: { type: Sequelize.STRING },
    userName: { type: Sequelize.STRING, unique: true },
    userPassword: { type: Sequelize.STRING, allowNull: false },
    gender: { type: Sequelize.BIGINT },
    birthday: { type: Sequelize.DATE },
    phone: { type: Sequelize.BIGINT, unique: true },
    address: { type: Sequelize.STRING },
    userRole: { type: Sequelize.BIGINT },
    picpath: { type: Sequelize.TEXT },
    resume: { type: Sequelize.TEXT },
    createdBy: { type: Sequelize.BIGINT },
    createdAt: { type: Sequelize.DATE },
    modifyBy: { type: Sequelize.BIGINT },
    updatedAt: { type: Sequelize.DATE },
  },
  {
    underscored: false,
    tableName: 'smbms_user',
  }
)
//设置外键关联
User.belongsTo(RoleModel, {
  foreignKey: 'userRole',
  targetKey: 'id',
  constraints: false,
})

module.exports = User
